{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.9 Laminar Flow in Valves, Fittings, and Pipe"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "SAE 30 oil at 100 deg F flows through a 5\" schedule 40 pipe at 400 gal/min.\n",
    "\n",
    "There is a sketch in the Crane document of the system.\n",
    "\n",
    "Find the velocity in feet/second and the pressure drop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(26.063989664869815 <Unit('pound_force_per_square_inch')>,\n",
       " 6.414177533606955 <Unit('foot / second')>)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from fluids.units import *\n",
    "from math import pi\n",
    "from fluids.constants import g\n",
    "g = g*u.m/u.s**2\n",
    "\n",
    "dH = 50*u.foot\n",
    "L = (175+50+75)*u.foot\n",
    "mu = 130*u.cP\n",
    "rho = (62.364*0.87)*u.lb/u.ft**3\n",
    "NPS, Di, Do, t = nearest_pipe(Do=5*u.inch, schedule='40')\n",
    "\n",
    "Q = 400*u.gallon/u.min\n",
    "A = 0.25*pi*Di**2\n",
    "\n",
    "v = Q/A\n",
    "Re = rho*v*Di/mu\n",
    "fd = friction_factor(Re=Re, eD=0.0018*u.inch/Di)\n",
    "ft = ft_Crane(Di)\n",
    "\n",
    "K_gate = K_gate_valve_Crane(D1=Di, D2=Di, fd=ft, angle=0.0*u.degrees)\n",
    "K_angle = K_angle_valve_Crane(D1=Di, D2=Di, fd=ft, style=1)\n",
    "K_elbow = bend_rounded(Di=Di, bend_diameters=1, angle=90*u.degrees, Re=Re, method='Crane')\n",
    "\n",
    "K_tot = K_elbow + K_gate + K_angle\n",
    "K_tot += K_from_f(fd=fd, L=L, D=Di)\n",
    "\n",
    "dP = dP_from_K(K=K_tot, rho=rho, V=v) + rho*g*dH\n",
    "dP.to(u.psi), v.to(u.foot/u.s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## Intermediate calculations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8.0 <Unit('dimensionless')>,\n",
       " 150.0 <Unit('dimensionless')>,\n",
       " 20.00000000000006 <Unit('dimensionless')>)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "K_gate/ft, K_angle/ft, K_elbow/ft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "29.991124449003742 dimensionless"
      ],
      "text/latex": [
       "$29.991124449003742\\ dimensionless$"
      ],
      "text/plain": [
       "29.991124449003742 <Unit('dimensionless')>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "K_tot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "6.414177533606955 foot/second"
      ],
      "text/latex": [
       "$6.414177533606955\\ \\frac{\\mathrm{foot}}{\\mathrm{second}}$"
      ],
      "text/plain": [
       "6.414177533606955 <Unit('foot / second')>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v.to(u.ft/u.s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0381948926809522 <Unit('dimensionless')>,\n",
       " 0.01543941031464228 <Unit('dimensionless')>)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fd, ft"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Proof system is laminar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "1675.616699190696 dimensionless"
      ],
      "text/latex": [
       "$1675.616699190696\\ dimensionless$"
      ],
      "text/plain": [
       "1675.616699190696 <Unit('dimensionless')>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Re.to(u.dimensionless)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
